#include <stdint.h>

#include "fixedpoint.h"

void getIntegerFraction(int32_t value, int decimals, int32_t *integer, int32_t *fraction) {
	*integer = FIX_TO_INT(value);
	*fraction = 10 * decimals * (value & ~(~((FIX_TYPE) 0) << FIX_FRACTION_LENGTH)) / (1 << FIX_FRACTION_LENGTH);
	*fraction = *fraction % 10 < 5 ? *fraction / 10 : *fraction / 10 + 1;
	if (*fraction == decimals) {
		*fraction = 0;
		++*integer;
	}
}
